package com.basaji.web.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class TrackFilter implements Filter{

	Logger log = Logger.getLogger(TrackFilter.class);
	
	public void destroy() {
        //EMPTY
    }

  
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
    	HttpServletRequest httpRequest = (HttpServletRequest) request;
    	//log.debug("ip:"+this.getRemoteIP(httpRequest));
    	//log.debug("url:"+httpRequest.getRequestURI());
        chain.doFilter(request, response);
    }

   
    public void init(FilterConfig arg0) throws ServletException {
        //EMPTY
    }

	public String getRemoteIP(HttpServletRequest request) {
		if (request.getHeader("x-forwarded-for") == null) {
			return request.getRemoteAddr();
		}
		return request.getHeader("x-forwarded-for");
	}

}
